package logic

import (
	"context"
	"post/api/internal/svc"
	"post/api/internal/types"
	"post/postrpc/postrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpadtePasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpadtePasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpadtePasswordLogic {
	return &UpadtePasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpadtePasswordLogic) UpadtePassword(req *types.UpadtePasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.PostRpc.UpdatePassword(l.ctx, &postrpc.UpdatePasswordRequest{
		Mobile:      req.Mobile,
		Password:    req.Password,
		NewPassword: req.NewPassword,
		SendSmsCode: req.SendSmsCode,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	} else {
		return &types.Response{
			Message: "忘记修改密码成功",
			Code:    200,
			Data:    update,
		}, nil

	}
}
